package simco.framework.gui.services.data;

import simco.framework.models.SimulationEvent;
import simco.framework.models.TypeEvent;

/**
 * Tato trida slouzi jako obalova trida pro objekty
 * typu {@link SimulationEvent}. Ke kazdemu objektu
 * reprezentujici udalost (v simulacnim jadre) udrzuje
 * take cas udalosti, jmeno cile a jmeno zdroje
 * udalosti.
 *
 * @author Matej Prokop, mythge@students.zcu.cz
 *
 */
public class SimulationEventWrapper 
{
	/**
	 * Cas udalosti
	 */
	private long eventTime;
	
	/**
	 * Reference na obaleny objekt, reprezentujici udalost v jadre
	 */
	private SimulationEvent event;
	
	/**
	 * Jmeno zdroje udalosti
	 */
	private String sourceName;
	
	/**
	 * Jmeno cile udalosti
	 */
	private String targetName;
	
	/**
	 * Znak kodujici udalost "zavolani"
	 */
	public static final char CALL_CHAR = 'C';
	
	/**
	 * Znak kodujici udalost "navrat z volani"
	 */
	public static final char RETURN_CHAR = 'R';

	/**
	 * Vytvori novou tridu obalujici udalost jadra
	 * 
	 * @param eventTime cas udalosti
	 * @param event reference na udalost jadra
	 * @param sourceName jmeno zdroje udalosti
	 * @param targetName jmeno cile udalosti
	 */
	public SimulationEventWrapper(long eventTime, SimulationEvent event,
			String sourceName, String targetName) 
	{		
		this.eventTime = eventTime;
		this.event = event;
		this.sourceName = sourceName;
		this.targetName = targetName;
	}

	/**
	 * Vraci cas udalosti (v jakem simulacnim case udalost probehne)
	 * @return cas udalosti
	 */
	public long getEventTime() 
	{
		return eventTime;
	}

	/**
	 * Vraci referenci na udalost jadra
	 * @return reference na udalost jadra
	 */
	public SimulationEvent getEvent() 
	{
		return event;
	}

	@Override
	public String toString() 
	{		
		char eventType = CALL_CHAR;
		if(event.getType() == TypeEvent.SIMULATION_RETURN || 
				event.getType() == TypeEvent.REAL_RETURN)
		{
			eventType = RETURN_CHAR;
		}
		
		return eventTime + ": [" + eventType + "] "+ sourceName + " - " + targetName;
	}
}

